package model;

import java.util.*;
import java.io.*;

public class TockChat implements Serializable{
	public static final long serialVersionUID = 0; // What the hell is this??
	
	private ArrayList<String> messages;
	private HashMap<String,String> messageUpdates;
	
	public TockChat() {
		messages = new ArrayList<String>();
		messageUpdates = new HashMap<String,String>();
		messages.add(" ");
	}
	
	public void setMessages(ArrayList<String> msgs) { messages = msgs; }
	public ArrayList<String> getMessages() { return messages; }
	
	public String getUpdate(String user) {
		String temp = messageUpdates.get(user);
		messageUpdates.put(user, "");
		return temp;		
	}
	
	public void addMessage(String msg) {
		messages.add(msg);
	}
	
	public void addUser(String user) {
		messageUpdates.put(user, "");
	}
	
	public void newMessage(String sender, String message) {
		String s = sender + ": " + message;
		messages.add(s);
		for (Iterator<String> it = messageUpdates.keySet().iterator(); it.hasNext(); ) {
			messageUpdates.put(it.next(), s);
		}
	}
	
	public void clear() {
		messages.clear();
	}
	
}
